from langchain.llms.loading import load_llm
from langchain.llms.openai import OpenAI
from langchain.load import dumpd, dumps, load, loads

print(OpenAI.is_lc_serializable())


def load_llm_test():
    llm_json = load_llm("llm.json")
    print(llm_json)
    llm_yaml = load_llm("llm.yaml")
    print(llm_yaml)


def save_llm():
    llm = OpenAI(model="gpt-3.5-turbo-instruct")
    llm.save("llm_save_json.json")
    llm.save("llm_save_yaml.yaml")


def dumpd_test():
    llm = OpenAI(model="gpt-3.5-turbo-instruct")
    # 加载为dict
    print(dumpd(llm))
    # 加载为字符串
    print(dumps(llm))
    loaded_1 = load(dumpd(llm))
    loaded_2 = loads(dumps(llm))
    print(loaded_1.invoke("How are you doing?"))


if __name__ == '__main__':
    save_llm()